package peace.graphic
{
import flash.display.Graphics;
import flash.geom.Point;
/**
 * 
 * Рисование чего-либо
 *  
 */
public class Painter
{
	
	/**
	 * 
	 * @param g
	 * @param begin
	 * @param end
	 * @param headLength
	 * @param headThickness
	 * @param bipolar
	 * 
	 */	
	public static function arrow (g:Graphics,
									begin:Point, end:Point,
									headLength:Number = 20,
									headThickness:Number = 5,
									bipolar:Boolean = false
									):void
	{
		// угол наклона отрезка стрелки
		var angle:Number = Math.atan2(end.y-begin.y, end.x-begin.x);

		// точка основания наконечника
		var bottomEndHead:Point = end.subtract(Point.polar(headLength,angle));

		// считаем точки наконечника
		var p1:Point = end;
		var p2:Point = bottomEndHead.add (Point.polar (headThickness/2, angle + Math.PI/2));
		var p3:Point = bottomEndHead.add (Point.polar (headThickness/2, angle - Math.PI/2));

		// рисуем наконечник
		g.moveTo(p1.x, p1.y);
		g.lineTo(p2.x, p2.y)
		g.lineTo(p3.x, p3.y)
		g.lineTo(p1.x, p1.y)

		// валим в точку основания
		g.moveTo(bottomEndHead.x, bottomEndHead.y);
		
		// рисуем палку
		if (! bipolar)
		{
			g.lineTo(begin.x, begin.y);
		}
		else
		{
		}
		
		// возвращаемся в конец
		g.moveTo(end.x, end.y);

	}
	/**
	 * 
	 * @param g
	 * @param begin
	 * @param end
	 * @param stroke
	 * @param gap
	 * 
	 */	
	public static function dottedLine (g:Graphics,
										begin:Point, end:Point,
										stroke:Number = 5, gap:Number = 3):void
	{
	
	}									
	/**
	 * 
	 * @param graphics
	 * @param x
	 * @param y
	 * @param w
	 * @param h
	 * @param radius
	 * @param lineColor
	 * @param fillColor
	 * @param lineThickness
	 * @param lineAlpha
	 * @param fillAlpha
	 * 
	 */	
	public static function roundRectAsFill (graphics:Graphics, 
												x:Number, y:Number, 
												w:Number, h:Number, 
												radius:Number,
												lineColor:uint, fillColor:uint=0xffffff,
												lineThickness:Number=1,
												lineAlpha:Number=1, fillAlpha:Number=1):void
	{
		graphics.lineStyle(0,0,0);
		graphics.beginFill(lineColor, lineAlpha);
		graphics.drawRoundRect(x, y, w, h, 2*radius, 2*radius);
		graphics.drawRoundRect(x+lineThickness, y+lineThickness, w-2*lineThickness, h-2*lineThickness, 2*radius-2*lineThickness, 2*radius-2*lineThickness);
		graphics.endFill();
		
		graphics.beginFill(fillColor,fillAlpha);
		graphics.drawRoundRect(x+lineThickness, y+lineThickness, w-2*lineThickness, h-2*lineThickness, 2*radius-2*lineThickness, 2*radius-2*lineThickness);
		graphics.endFill();
	}											
	
	
}
}